//
//  JFNavigationController.m
//  KaKa
//
//  Created by junFung on 15/12/17.
//  Copyright © 2015年 yc. All rights reserved.
//

#import "JFNavigationController.h"
#import "JFNavigationBar.h"

@interface JFNavigationController ()<UINavigationControllerDelegate>

@end

@implementation JFNavigationController

+ (void)initialize
{
    //1.设置导航条的背景图片，设置全局的背景图片
    UINavigationBar *navBar = [UINavigationBar appearanceWhenContainedIn:self, nil];
    navBar.barTintColor = [UIColor whiteColor];
    
    //2.设置导航条标题字体大小以及颜色
    NSDictionary *barDic = @{
                             NSFontAttributeName:[UIFont systemFontOfSize:16.0],
                             NSForegroundColorAttributeName:COLOR_Theme
                             };
    [navBar setTitleTextAttributes:barDic];
    
    //3.设置返回按钮的样式
    //tintColor适用于所有导航条上的item
    navBar.tintColor = COLOR_Theme;
    
    //4.设置item的字体大小和颜色
    UIBarButtonItem *barItem = [UIBarButtonItem appearanceWhenContainedIn:self, nil];
    
    NSDictionary *itemDic = @{
                              NSFontAttributeName:[UIFont systemFontOfSize:13.0],
                              NSForegroundColorAttributeName:COLOR_Theme
                              };
    [barItem setTitleTextAttributes:itemDic forState:UIControlStateNormal];
    
}

- (void)viewDidLoad {
    [super viewDidLoad];
    UIWindow *window = [UIApplication sharedApplication].keyWindow;
    
    JFNavigationBar *bar = [[JFNavigationBar alloc] initWithFrame:CGRectMake(0, 20, window.frame.size.width, 44)];
    [self setValue:bar forKey:@"navigationBar"];
}

#pragma mark --- 拦截所有push的viewController

- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated
{
    /*
     * 而self.viewControllers里面是所有push的viewController，以栈的形式存在
     */
    if (self.viewControllers.count > 0) {
        
        NSLog(@"----------push----------");
    }
    [super pushViewController:viewController animated:animated];
}

@end
